/*
 * Project: com.mmall.order.helper
 *
 * File Created at 2019-10-27
 *
 * Copyright 2019 CMCC Corporation Limited.
 * All rights reserved.
 *
 * This software is the confidential and proprietary information of
 * ZYHY Company. ("Confidential Information").  You shall not
 * disclose such Confidential Information and shall use it only in
 * accordance with the terms of the license.
 */
package com.mmall.order.helper;

import com.common.framework.constant.Constants;
import com.common.framework.util.CacheUtils;
import com.common.framework.util.DateUtil;
import com.mmall.common.spring.service.RedisService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import java.util.Date;

/**
 * @author jianghucoding
 * @date 2019-10-27
 */
@Component
public class OrderNumberGenerateHelper {

    @Autowired
    private RedisService redisService;

    public long generateOrderNumber() {
        String date = DateUtil.formatToString(new Date(), Constants.YYYYMMDDHH);
        Long sequence = redisService.vIncr(CacheUtils.CacheName.ORDER_NUMBER_SEQUENCE, "", 1L);
        return Long.valueOf(date.concat(String.valueOf(sequence)));
    }
}
